package com.xuexiang.yoyo.constant;

import com.fcat.base.common.util.StrUtil;
import com.xuexiang.yoyo.sql.DataBaseOpenHelper;
import com.xuexiang.yoyo.sql.mapper.KeyValueMapper;

public class HesAppStatic {
    private static int protocalSelectIndex = -1;


    private static int communicationSelectIndex = -1;

    private static int baudSelectIndex = -1;

    private static String readingDeviceId = "002207120014";
    private static String readingDeviceCodeVirtually = "002207120014";

    private static boolean connectFlag = false;
    private static boolean pressTestFlag;
    private static DataBaseOpenHelper mDataBaseOpenHelper;
    private static String pressTestNum;

    public static String getReadingDeviceCodeVirtually() {
        return readingDeviceCodeVirtually;
    }

    public static void setReadingDeviceCodeVirtually(String readingDeviceCodeVirtually) {
        HesAppStatic.readingDeviceCodeVirtually = readingDeviceCodeVirtually;
    }

    public static boolean isConnectFlag() {
        String value = KeyValueMapper.queryValueByKey(HesAppConstant.DB_Key_ConnectFlag);
        if(!StrUtil.isBlank(value)){
            connectFlag = Boolean.valueOf(value);
        }
        return connectFlag;
    }

    public static void setConnectFlag(boolean connectFlag) {
        HesAppStatic.connectFlag = connectFlag;
        KeyValueMapper.insert(HesAppConstant.DB_Key_ConnectFlag,String.valueOf(connectFlag));
    }



    public static boolean isPressTestFlag() {
        String value = KeyValueMapper.queryValueByKey(HesAppConstant.DB_Key_PressTestFlag);
        if(!StrUtil.isBlank(value)){
            pressTestFlag = Boolean.valueOf(value);
        }
        return pressTestFlag;
    }

    public static void setPressTestFlag(boolean pressTestFlag) {
        HesAppStatic.pressTestFlag = pressTestFlag;
        KeyValueMapper.insert(HesAppConstant.DB_Key_PressTestFlag,String.valueOf(pressTestFlag));
    }

    public static DataBaseOpenHelper getmDataBaseOpenHelper() {
        return mDataBaseOpenHelper;
    }

    public static void setmDataBaseOpenHelper(DataBaseOpenHelper mDataBaseOpenHelper) {
        HesAppStatic.mDataBaseOpenHelper = mDataBaseOpenHelper;
    }

    public static String getUsername() {
        String username = KeyValueMapper.queryValueByKey(HesAppConstant.DB_Key_username);
        if(StrUtil.isBlank(username))username = "";
        return username;
    }

    public static void setUsername(String username) {
        if(!StrUtil.isBlank(username)){
            KeyValueMapper.insert(HesAppConstant.DB_Key_username,username);
        }
    }

    public static String getPassword() {
        return KeyValueMapper.queryValueByKey(HesAppConstant.DB_Key_password);
    }

    public static void setPassword(String password) {
        if(!StrUtil.isBlank(password)){
            KeyValueMapper.insert(HesAppConstant.DB_Key_password,password);
        }
    }

    public static void setBaudSelectIndex(int baudSelectIndex) {
        String value1 = ""+baudSelectIndex;
        KeyValueMapper.insert(HesAppConstant.DB_Key_BaudSelectIndex,value1);
        HesAppStatic.baudSelectIndex = baudSelectIndex;
    }

    public static String getSelectProtocal(){
        return HesAppConstant.protocalList[getProtocalSelectIndex()];
    }
    public static String getSelectCommunication(){
        return HesAppConstant.communicationList[getCommunicationSelectIndex()];
    }

    public static int getProtocalSelectIndex() {
        if(protocalSelectIndex==-1) {
            String value = KeyValueMapper.queryValueByKey(HesAppConstant.DB_Key_ProtocalSelectIndex);
            if (!StrUtil.isBlank(value)) {
                protocalSelectIndex = Integer.valueOf(value);
            }else{
                protocalSelectIndex = 0;
            }
        }
        return protocalSelectIndex;
    }

    public static void setProtocalSelectIndex(int protocalSelectIndex) {
        String value1 = ""+protocalSelectIndex;
        KeyValueMapper.insert(HesAppConstant.DB_Key_ProtocalSelectIndex,value1);
        HesAppStatic.protocalSelectIndex = protocalSelectIndex;
    }

    public static int getCommunicationSelectIndex() {

        if(communicationSelectIndex==-1) {
            String value = KeyValueMapper.queryValueByKey(HesAppConstant.DB_Key_CommunicationSelectIndex);
            if (!StrUtil.isBlank(value)) {
                communicationSelectIndex = Integer.valueOf(value);
            }else{
                communicationSelectIndex = 0;
            }
        }
        return communicationSelectIndex;
    }

    public static void setCommunicationSelectIndex(int communicationSelectIndex) {
        String value1 = ""+communicationSelectIndex;
        KeyValueMapper.insert(HesAppConstant.DB_Key_CommunicationSelectIndex,communicationSelectIndex+"");
        HesAppStatic.communicationSelectIndex = communicationSelectIndex;
    }

    public static String getReadingDeviceId() {
        readingDeviceId = KeyValueMapper.queryValueByKey(HesAppConstant.DB_Key_ReadingDeviceId);
        return readingDeviceId;
    }

    public static void setReadingDeviceId(String readingDeviceId) {
        if(!StrUtil.isBlank(readingDeviceId))KeyValueMapper.insert(HesAppConstant.DB_Key_ReadingDeviceId,readingDeviceId+"");
        HesAppStatic.readingDeviceId = readingDeviceId;
    }
    public static int getPressTestNum() {
        if(StrUtil.isBlank(pressTestNum)){
            pressTestNum = KeyValueMapper.queryValueByKey(HesAppConstant.DB_Key_PressTestNum);
            if(StrUtil.isBlank(pressTestNum)){
                pressTestNum="1";
            }
        }
        return Integer.valueOf(pressTestNum);
    }

    public static void setPressTestNum(String pressTestNum) {
        if(!StrUtil.isBlank(pressTestNum))KeyValueMapper.insert(HesAppConstant.DB_Key_PressTestNum,pressTestNum);
        HesAppStatic.pressTestNum = pressTestNum;
    }
}
